package cn.yougou.serviceImpl;


import cn.yougou.mapper.YgAdminMapper;
import cn.yougou.mapper.YgCommodityMapper;
import cn.yougou.mapper.YgOrderMapper;
import cn.yougou.mapper.YgUserMapper;
import cn.yougou.pojo.YgAdmin;
import cn.yougou.service.admin.YgAdminService;
import cn.yougou.vo.YgCountVo;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * (YgAdmin)表服务实现类
 *
 * @author 白杰崇
 * @since 2020-12-03 01:32:18
 */
@Service
public class YgAdminServiceImpl implements YgAdminService {

    @Autowired
    private YgAdminMapper ygAdminMapper;
    @Autowired
    private YgUserMapper ygUserMapper;
    @Autowired
    private YgCommodityMapper ygCommodityMapper;
    @Autowired
    private YgOrderMapper ygOrderMapper;


    /**
     * 查询商品,用户,订单的数据量
     * @return 数据量
     */
    public YgCountVo countVo(){
        YgCountVo count = new YgCountVo(ygUserMapper.uCount(),ygCommodityMapper.cdCount(),ygOrderMapper.OrderCount());
        return count;
    }




    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public YgAdmin queryById(Integer id) {
        return this.ygAdminMapper.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<YgAdmin> queryAllByLimit(int offset, int limit) {
        return this.ygAdminMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param ygAdmin 实例对象
     * @return 实例对象
     */
    @Override
    public YgAdmin insert(YgAdmin ygAdmin) {
        this.ygAdminMapper.insert(ygAdmin);
        return ygAdmin;
    }

    /**
     * 修改数据
     *
     * @param ygAdmin 实例对象
     * @return 实例对象
     */
    @Override
    public YgAdmin update(YgAdmin ygAdmin) {
        this.ygAdminMapper.update(ygAdmin);
        return this.queryById(ygAdmin.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.ygAdminMapper.deleteById(id) > 0;
    }


}